package com.annhoa.security.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.annhoa.system.domain.User;
import com.annhoa.system.repository.UserRepository;

/**
 * 1，处理用户信息获取，2,用户校验，3密码的加密解密
 */
public class CustomUserService implements UserDetailsService {
    @Autowired
    UserRepository userRepository;
    
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
    	
    	 String password = passwordEncoder.encode("123456");
         //System.err.println("加密后密码：  "+password);
    	
        User user = userRepository.findByUsername(s);
        if (user == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }

        return user;
    }
}
